package sql;

/**
 * Created by luozhen on 2016/8/4.
 */

import java.sql.*;

public class SqlDate {

    public static void main(String[] args){

        Connection connection = null;
        ResultSet resultSet = null;
        PreparedStatement preparedStatement = null;
        try {
//        // 驱动程序名
//        String driver = "com.mysql.jdbc.Driver";
//
//        // URL指向要访问的数据库名scutcs
//        String url = "jdbc:mysql://127.0.0.1:3306/scutcs";
//
//        // MySQL配置时的用户名
//        String user = "root";
//
//        // MySQL配置时的密码
//        String password = "110625";


            Connection con = null; //定义一个MYSQL链接对象
            Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动
            con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/scutcs", "root", "110625"); //链接本地MYSQL

            Statement stmt; //创建声明
            stmt = con.createStatement();

            //新增一条数据
            stmt.executeUpdate("INSERT INTO student (username, password) VALUES ('init', '123456')");
            ResultSet res = stmt.executeQuery("select LAST_INSERT_ID()");
            int ret_id;
            if (res.next()) {
                ret_id = res.getInt(1);
                System.out.print(ret_id);
            }

        } catch (Exception e) {
            System.out.print("MYSQL ERROR:" + e.getMessage());
        }



    }
}